package com.mpyy.handler.inventory;

import com.alibaba.fastjson.JSON;
import com.mpyy.pojo.InventoryDesc;
import com.mpyy.pojo.ProductInfo;
import com.mpyy.service.inventory.AlarmInventoryMapperServiceInter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
public class AlarmInventoryController {
    /*连接service层*/
    @Autowired
    @Qualifier(value = "alarmInventoryMapperServiceImpl")
    private AlarmInventoryMapperServiceInter alarmInventoryMapperServiceInter;

    /*查询库存数量到下限的商品*/
    @RequestMapping(value = {"/searchAlarmCommodity"})
    @ResponseBody
    public String searchAlarmCommodity(){
        List<InventoryDesc> inventoryDescs = alarmInventoryMapperServiceInter.searchAlarmCommodity();

        //创建一个Map
        HashMap<Object, Object> inventoryDescHashMap = new HashMap<>();
        inventoryDescHashMap.put("code",0);
        inventoryDescHashMap.put("msg","");
        inventoryDescHashMap.put("count",inventoryDescs.size());
        inventoryDescHashMap.put("data",inventoryDescs);

        System.out.println(inventoryDescHashMap);
        return JSON.toJSONString(inventoryDescHashMap);
    }

    /*修改商品库存下限的值*/
    @RequestMapping(value = "updateProductInfoproStockLower/{proStockLower}/{proId}")
    @ResponseBody
    public int updateProductInfoproStockLower(@PathVariable("proStockLower") Integer proStockLower,
                                              @PathVariable("proId") String proId){
        ProductInfo productInfo = new ProductInfo();
        productInfo.setProId(proId);
        productInfo.setProStockLower(proStockLower);
        return alarmInventoryMapperServiceInter.updateProductInfoproStockLower(productInfo);
    }
}
